package com.chenjun.core.service.atten.impl;

import java.util.Calendar;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.chenjun.common.bean.Pagination;
import com.chenjun.common.model.DataGridModel;
import com.chenjun.core.dao.generator.entity.OaDictAttnType;
import com.chenjun.core.dao.generator.mapper.OaDictAttnTypeMapper;
import com.chenjun.core.dao.module.OaDictAttnTypeRelationMapper;
import com.chenjun.core.service.atten.AttendanceModeSettingService;


/**
 * 
 * @Description: 考勤方式设置Service
 * @author yanjinyin
 * @date 2017年8月29日 下午9:41:56
 */
@Service
public class AttendanceModeSettingServiceImpl implements AttendanceModeSettingService  {
	
	@Resource
	private OaDictAttnTypeMapper atMapper;
	
	@Resource
	private OaDictAttnTypeRelationMapper atRelationMapper;

	@Override
	public OaDictAttnType get(Integer id) {
		return atMapper.selectByPrimaryKey(id);
	}

	@Override
	public int delete(Integer id) {
		return atMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int createOrUpdate(OaDictAttnType record) {
		int rows = 0;
		Calendar date = Calendar.getInstance();
		if (record.getId() == null) {
			record.setCreateTime(date.getTime());
			record.setUpdateTime(date.getTime());
			rows = atMapper.insert(record);
		} else {
			record.setUpdateTime(date.getTime());
			rows = atMapper.updateByPrimaryKeySelective(record);
		}
		return rows;
	}

	@Override
	public Pagination doPagination(DataGridModel param) {
		Pagination vo = new Pagination();
		List<OaDictAttnType> list = atRelationMapper.selectByCondition(param);
		param.setStart(0);
		param.setRows(0);
		int size = atRelationMapper.countByCondition(param);
		vo.setAaData(list);
		vo.setiTotalRecords(size);
		vo.setsEcho(param.getPage());
		vo.setiTotalDisplayRecords(size);
		return vo;
	}


}
